﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NewsMine.DomainObjects;

namespace NewsDiscoveryEngine.Cleansing
{
    /// <summary>
    /// This class allows to manage all kinds of cleaning activities at all levels.
    /// 
    /// There will be configurable cleaners that will involve and clean the feedItems or Urls;
    /// 
    /// Having Global filters, websiteLevel filters and also menu level filters which will make sure that the rules will transform the to correct format.
    /// 
    /// Expecting to clean feedItems, Urls as of now. we can keep adding to this class.
    /// todo:needs to be implemented.
    /// </summary>
    public static class CleansingManager
    {
        static List<ICleanser> cleansers = new List<ICleanser>();
        static CleansingManager()
        {
            // todo: here we need to have the initialization. This spot can be used to read all the configurations for the cleasing.
            // and also add all the available cleansers.

            cleansers.Add(new UrlCleanser());
            cleansers.Add(new TitleBasedCleaner());
            cleansers.Add(new ImageCleanser());
        }

        public static List<HtmlLink> Cleanse(List<HtmlLink> htmlLinks)
        {
            
            //todo: here we need to validate each and every feed item that is there in the list and remove the invalid items and return only valid items.
            //We are going to use all cleansing techniques to check feed's validity.
            // if the url contains the segments that becomes the invalid item.
            // if the title is contains only number not any thing that becomes the invalid item.
            // if the title contains only one word, that is listed in our menu list or reserved keyworkds, consider that as the invalid item.

            

            foreach (var cleanser in cleansers)
            {
                htmlLinks = cleanser.Cleanse(htmlLinks);
            }

            return htmlLinks;
        }
        
    }
}
